package cn.jm.xml;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonStudy {
	
	
	public List<Map<String, String>> builderData() {
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		Map<String, String> item = new HashMap<String, String>();
		item.put("name", "张三");
		item.put("sex", "男");
		data.add(item);
		item = new HashMap<String, String>();
		item.put("name", "李四");
		item.put("sex", "女");
		data.add(item);
		item = new HashMap<String, String>();
		item.put("name", "王四");
		item.put("sex", "男");
		data.add(item);
		item = new HashMap<String, String>();
		item.put("name", "邵明");
		item.put("sex", "女");
		data.add(item);
		for(int i=0 ; i<100;i++) {
			item = new HashMap<String, String>();
			item.put("name", "邵明"+i);
			item.put("sex", "女");
			data.add(item);
		}

		return data;
	}
	
	public void write() {
		List<Map<String, String>> data =builderData();
		ObjectMapper mapper = new ObjectMapper(); //转换器
		try {

			mapper.writeValue(new File("output.json"), data);
			
			
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
